﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace MediaRegister
{
    public partial class NyKund : Form
    {
        private struct nyKund
        {
            public string Namn;
            public string Personnr;
            public string Email;
            public string telnr; 
            public string Adress;
        }

        public int ny1;

        public NyKund()
        {
            InitializeComponent();
        }
       
        public NyKund(int ny)
        {
            ny = ny1;
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            nyKund ny;
            ny.Namn = textBox1.Text;
            ny.Personnr = textBox2.Text;
            ny.Email = textBox3.Text;
            ny.telnr = textBox4.Text;
            ny.Adress = textBox5.Text;
            FileStream fs1 = new FileStream(@"M:\nykund.txt", FileMode.Append, FileAccess.Write);
            StreamWriter sr1 = new StreamWriter(fs1);
            sr1.WriteLine(ny.Namn + " , " + ny.Personnr + " , " + ny.Email + " , " + ny.telnr + " , "+ ny.Adress);
            foreach (Control t in this.Controls)
                if (t is TextBox)
                    t.Text = " ";
            sr1.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            String s1;
            if (File.Exists(@"M:\nykund.txt"))
            {
                FileStream fs1 = new FileStream(@"M:\nykund.txt", FileMode.Open, FileAccess.Read);
                StreamReader sr1 = new StreamReader(fs1);
                s1 = sr1.ReadLine();
                while (s1 != null)
                {
                    listBox1.Items.Add(s1);
                    s1 = sr1.ReadLine();
                }
                sr1.Close();
            }

            else
            {
                MessageBox.Show("Finns ingen fil att visa");
            }
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
